package edu.hqu.experiment3_h2.controller;

import edu.hqu.experiment3_h2.dao.UserRepository;
import edu.hqu.experiment3_h2.pojo.User;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class UserController {
    @Autowired
    private UserRepository userRepository;
    @GetMapping("/user/{id}")// 注意，此处使用的是 GetMapping 注解，该注解的作用类似与@RequestMapping (value="/user/{id}", method= RequestMethod. GET)，@PostMapping 注解同理
    public User findById(@PathVariable Long id) {
        return this.userRepository.findById(id).orElse(null);
    }
}